(function() {
    angular.module('app').component('shopControllerComponent', {
        templateUrl: 'app/controllers/shop.controller/shop.controller.component/shop.controller.component.html',
        controller: shopControllerComponent,
        controllerAs: 'vm',
        bindings: {
            filter: '<'
        }
    });

    shopControllerComponent.$inject = ['shopControllerComponentService', 'PagerService', '$scope', 'tableBrandShopsService', '$rootScope', 'util', '$loading', '$timeout','$controller'];

    function shopControllerComponent(shopControllerComponentService, PagerService, $scope, tableBrandShopsService, $rootScope, util, $loading, $timeout,$controller) {

        var vm = this;

        // console.log('shopControllerComponent js loading');
        // console.log(vm.filter);

        vm.table = {
            count: 0,
            shops: []
        };

        vm.$onInit  = function(){

            angular.extend(vm, $controller('commonCtrl', {$scope: $scope}));//controller的扩张

            //设置分页函数实现
            vm.pager.pagerChange = pagerChange; 
            pagerChange();
        };


        function pagerChange() {

            vm.param = util.extend(vm.param, vm.pager);


            $loading.start('tableShopLoading');
            shopControllerComponentService.get(vm.param).then(function(data) {

                // vm.table.count = data.count/10*11;
                vm.pager.setAllPageCount(data.count);

                vm.table.shops = data.shopInfos;

                angular.forEach(vm.table.shops, function(item, index) {
                    item = util.shopLevelFormat(item);
                    //店铺等级

                });

                tableBrandShopsService.shopBasicInit(); //店铺详情的序号
                tableBrandShopsService.monitorDataInit(); //日监控所在的序号

                $timeout(function() {
                    $loading.finish('tableShopLoading');
                }, 500);


            }, function() {
                $loading.finish('tableShopLoading');
            });


        }







        //获取店铺详细监控
        vm.getShopBasic = tableBrandShopsService.getShopBasic; //function

        //获取日监控
        vm.getMonitorData = tableBrandShopsService.getMonitorData; //function

        //发送广播分别到table.list.component和table.shop.prods
        vm.getBrandShopProds = getBrandShopProds; //function


        function getBrandShopProds(shop) {
            //发送广播分别到table.list.component和table.shop.prods
            $rootScope.$emit('formBrandShop_detail_EV', shop.userId, shop.shopName);
        }


    }
})();
